const express = require('express')
const app = express()
const bodyParser = require("body-parser")
const port = 3000 // 端口号

// 文件操作
const path = require('path')

// 处理post数据的提交
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
	extended: false
}));

// 配置静态资源路径
app.use(express.static(path.join(__dirname, 'data')));

// 解决跨域
app.all('*', function(req, res, next) {
	res.header('Access-Control-Allow-Origin', '*');
	res.header('Access-Control-Allow-Headers', 'Content-Type');
	res.header('Access-Control-Allow-Methods', '*');
	res.header('Content-Type', 'application/json;charset=utf-8');
	next();
});

// 引用路由文件
require('./router/fileRouter.js')(app)
require('./router/router.js')(app)

app.listen(port, () => console.log(`文轩阁服务器启动成功，端口号为： ${port}!`))
